<?php
class QdketnapsController extends AppController {

	var $name = 'Qdketnaps';

	function index() {
		$this->Qdketnap->recursive = 0;
		$this->set('qdketnaps', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid qdketnap', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('qdketnap', $this->Qdketnap->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Qdketnap->create();
			if ($this->Qdketnap->save($this->data)) {
				$this->Session->setFlash(__('The qdketnap has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The qdketnap could not be saved. Please, try again.', true));
			}
		}
		$sinhviens = $this->Qdketnap->Sinhvien->find('list');
		$ketnapdvs = $this->Qdketnap->Ketnapdv->find('list');
		$this->set(compact('sinhviens', 'ketnapdvs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid qdketnap', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Qdketnap->save($this->data)) {
				$this->Session->setFlash(__('The qdketnap has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The qdketnap could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Qdketnap->read(null, $id);
		}
		$sinhviens = $this->Qdketnap->Sinhvien->find('list');
		$ketnapdvs = $this->Qdketnap->Ketnapdv->find('list');
		$this->set(compact('sinhviens', 'ketnapdvs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for qdketnap', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Qdketnap->delete($id)) {
			$this->Session->setFlash(__('Qdketnap deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Qdketnap was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>